import axios from './ajax'

// 1.登录接口

export const reqLogin = (loginForm) => {
  // console.log(loginForm)
  return axios({
    method: 'post',
    url: '/login',
    data: loginForm
    // {
    //   username: loginForm.username,
    //   password: loginForm.password
    // }
  })
}

// 2.获取左侧菜单数据
export const reqMenuList = () => {
  return axios({
    method: 'get',
    url: '/menus'
  })
}

// -----------------------------------------------用户管理------------------------------------------------------------------
// 3.获取用户数据
export const reqUserList = (params) => {
  // console.log(params)
  return axios({
    method: 'get',
    url: '/users',
    params: params
  })
}

// 4.修改用户状态
// users/:uId/state/:type  put
export const reqChangeUserStatus = (id, type) => {
  return axios({
    method: 'put',
    url: `users/${id}/state/${type}`
  })
}

// 5.添加用户
export const reqGetusers = (params) => {
  // console.log(params)
  return axios({
    method: 'post',
    url: '/users',
    data: params
  })
}

// 6.根据ID查询用户数据
// users/:id
export const reqGetusersById = (ID) => axios({
  method: 'get',
  url: `/users/${ID}`
})

// 7.编辑用户提交
// users/:id  put
export const reqEditUsersById = (ID, data) => axios({
  method: 'put',
  url: `/users/${ID}`,
  data: data
})

// 8.删除用户
// users/:id delete
export const reqDeleteUserById = (ID) => axios({
  method: 'delete',
  url: `/users/${ID}`
})

// ---------------------------------------------------权限管理-----------------------------------------------------------

// 9.所有权限列表
// rights/:type   get
export const reqGetRights = (type) => {
  return axios({
    method: 'get',
    url: `/rights/${type}`
  })
}

// 10.获取所有角色列表
// roles  get
export const reqGetRoles = () => {
  return axios({
    method: 'get',
    url: '/roles'
  })
}

// 11.删除角色下指定功能
// roles/:roleId/rights/:rightId
// delete
export const reqDeleteRight = (roleId, rightId) => {
  return axios({
    method: 'delete',
    url: `roles/${roleId}/rights/${rightId}`
  })
}

// 12.角色授权
// roles/:roleId/rights  post
export const reqAllotRight = (roleId, rids) => {
  console.log(roleId, rids)
  return axios({
    method: 'post',
    url: `roles/${roleId}/rights`,
    data: {
      rids: rids
    }
  })
}

// export const reqAllotRight = (roleId, rids) => {
//   return axios.post(`roles/${roleId}/rights`, {
//     rids: rids
//   })
// }

// 13. 分配用户角色
// 请求路径：users/:id/role  put
export const reqAuthorizeRole = (roleId, rid) => {
  console.log(roleId, rid)
  return axios({
    method: 'put',
    url: `users/${roleId}/role`,
    data: {
      rid: rid
    }
  })
}

// export const reqAuthorizeRole
